/**
 * 
 */
package cn.ad.server.web.service;

import cn.ad.server.persistence.dao.SysConfigDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * 系统配置接口服务
 * @author WU CHENGJUN
 */
@Service
public class SysconfigService {
	
	@Autowired
	SysConfigDao sysConfigDao;

	/**
	 * 更新系统配置
	 * @param newValueMap
	 * @return
	 * @throws BizServiceException 
	 */
	@Transactional(rollbackFor=Exception.class)
	public boolean updateConfigValue(Map<String, String> newValueMap) throws BizServiceException{
		Assert.notNull(newValueMap);
		for(String key : newValueMap.keySet()){
			int result = sysConfigDao.updateValue(key, newValueMap.get(key));
			if(result == 0){
				throw new BizServiceException("更新系统配置出现异常: configKey:[" + key + "]  configValue:[" + newValueMap.get(key) + "]");
			}
		}
		return true;
	}
}
